using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using BUS;
using Utility;
using System.Data.SqlClient;
public partial class admin_A_DoanhNghiep : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddata();
        }
       
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {

            DoanhNghiep_DTO dn = (DoanhNghiep_DTO)e.Item.DataItem;
        //    HyperLink hplsua = (HyperLink)e.Item.FindControl("hplsua");
        //    hplsua.NavigateUrl = "~/admin/A_DoanhNghiep_update.aspx?madn=" + dn.MaDN.ToString();
        //    ////hplsua.NavigateUrl = "~/admin/A_loaihang_update.aspx";

            #region"hinh ban do"
            //Image hinhbando = (Image)e.Item.FindControl("i_hinhbando");
            Image hinhbando = (Image)e.Item.FindControl("i_hinhbando");

            hinhbando.ImageUrl = "~/photos/Thumb/" + dn.BanDo;
            #endregion

           

        }
    }
    private void loaddata()
    {
       
        Criteria cri = new Criteria();
        int total = 0;
        ptloaihang.PageSize = 5;
        if (txttendn.Text != "")
        {
            cri.add(Condition.AND, tbDoanhNghiepColumns.TenDN, Condition.LIKE, txttendn.Text);
        }
        if (txtmadn.Text != "")
        {
            cri.add(Condition.AND, tbDoanhNghiepColumns.MaDN, Condition.EQUAL, int.Parse(txtmadn.Text));
        }

        tbDoanhNghiepCollection lh = DoanhNghiep_BUS.Get(cri.Criter, ptloaihang.CurrentIndex, ptloaihang.PageSize, tbDoanhNghiepColumns.MaDN.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = lh;
        Repeater1.DataBind();
        ptloaihang.ItemCount = total;


    }
    public bool IsNumeric(string val)
    {
        double result;
        return double.TryParse(val, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.CurrentInfo, out result);
    }

    
    protected void bttimkiem_Click(object sender, EventArgs e)
    {
        //string maloai = txtmadn.Text;

        //if (IsNumeric(maloai) == false)
        //{
        //    txtmadn.ForeColor = Color.Red;
        //    // loaddata();
        //    return;
        //}
        //else
        //{

        //    txtmadn.ForeColor = Color.Black;
        loaddata();

        //}
            
    }
    protected void ptloaihang_Command(object sender, CommandEventArgs e)
    {
        ptloaihang.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        loaddata();
    }
    protected void lbt_x_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                CheckBox cxoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
                if (cxoa.Checked == true)
                {
                    HiddenField hdf = (HiddenField)Repeater1.Items[i].FindControl("hdmadn");
                    int ma = int.Parse(hdf.Value);
                    DoanhNghiep_BUS.Delete(ma);

                }
            }
            Response.Redirect(Request.RawUrl);
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }

    }
}
